package com.emellend.api.chronometer;

import com.emellend.api.R;

import android.app.Activity;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Chronometer;
/**
 * 计时器
 * @author emellend
 *
 */
public class ChronometerDemo extends Activity implements OnClickListener {
	private Chronometer mChronometer;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chronometer);
		init();
	}

	private void init() {
		mChronometer = (Chronometer) this.findViewById(R.id.chronometer);
		findViewById(R.id.start).setOnClickListener(this);
		findViewById(R.id.stop).setOnClickListener(this);
		findViewById(R.id.reset).setOnClickListener(this);
		findViewById(R.id.set_format).setOnClickListener(this);
		findViewById(R.id.clear_format).setOnClickListener(this);
	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.start:
			mChronometer.start();
			break;
		case R.id.stop:
			mChronometer.stop();
			break;
		case R.id.reset:
			mChronometer.setBase(SystemClock.elapsedRealtime());
			break;
		case R.id.set_format:
			mChronometer.setFormat("Formatted time (%s)");
			break;
		case R.id.clear_format:
			mChronometer.setFormat(null);
			break;
		}
	}
}
